import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: bask
 * @Date: 2022/4/2 14:23
 */
public class Duration {
    public long time(String time1, String time2,Boolean springChange, Boolean fallChange) {
        long minute = 0;
        try {
            //日期格式化，将字符串转为日期
            SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmmss");
            Date date1 = format1.parse(time1);
            Date date2 = format1.parse(time2);
            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(date1);
            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(date2);

            //返回毫秒
            long phonetime = date2.getTime() - date1.getTime();

            //不到一分钟按一分钟计算
            if(phonetime>=0 && phonetime/1000<60 || phonetime%60000>0){
                minute = phonetime/1000/60+1;
            }else{
                minute = phonetime/1000/60;
            }

            //通话存在春时制与夏时制转换
            if(springChange) {
                minute -= 60;
            }

            //通话存在夏时制与秋时制转换
            if(fallChange) {
                minute+=60;
            }

        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return minute;
    }
}
